// components/select/select.js
var util = require("../../utils/util.js");
Component({
  properties: {
    accordion: {
      type: Boolean,
      value: false
    },
    sorts: {
      type: Array,
      value: ["综合排序", "销量优先", "价格由高到低", "价格由低到高"]
    },
    majorSup: {
      type: Array,
      value: [{
        id: 0,
        plabel: "1",
        show: false,
        title: "舞蹈",
        iconChecked: "icon",
        majorSub: [
          { pId: 0, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 0, id: 1, title: "古典舞基本功", type: "default", LabelID: "1_1" },
          { pId: 0, id: 2, title: "技术技巧", type: "default", LabelID: "1_2" },
          { pId: 0, id: 3, title: "民族民间舞", type: "default", LabelID: "1_3" },
          { pId: 0, id: 4, title: "舞蹈剧目", type: "default", LabelID: "1_4" },
          { pId: 0, id: 5, title: "舞蹈编导", type: "default", LabelID: "1_5" },
          { pId: 0, id: 6, title: "舞蹈技巧", type: "default", LabelID: "1_6" }
        ]
      }, {
        id: 1,
        plabel: "2",
        show: false,
        title: "表演",
        iconChecked: "icon",
        majorSub: [
          { pId: 1, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 1, id: 1, title: "声乐", type: "default", LabelID: "2_1" },
          { pId: 1, id: 2, title: "台词", type: "default", LabelID: "2_2" },
          { pId: 1, id: 3, title: "形体", type: "default", LabelID: "2_3" },
        ]
      },
      {
        id: 2,
        plabel: "3",
        title: "书法",
        iconChecked: "icon",
        majorSub: [
          { pId: 2, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 2, id: 1, title: "临帖", type: "default", LabelID: "3_1" },
          { pId: 2, id: 2, title: "创作", type: "default", LabelID: "3_2" },
          { pId: 2, id: 3, title: "篆刻", type: "default", LabelID: "3_3" },
        ]
      }, {
        id: 3,
        plabel: "4",
        title: "空乘",
        iconChecked: "icon",
        majorSub: [
          { pId: 3, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 3, id: 1, title: "形体", type: "default", LabelID: "4_1" },
          { pId: 3, id: 2, title: "口语", type: "default", LabelID: "4_2" },
          { pId: 3, id: 3, title: "姿势", type: "default", LabelID: "4_3" },
        ]
      }, {
        id: 4,
        plabel: "5",
        title: "美术",
        iconChecked: "icon",
        majorSub: [
          { pId: 4, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 4, id: 1, title: "素描", type: "default", LabelID: "5_1" },
          { pId: 4, id: 2, title: "色彩", type: "default", LabelID: "5_2" },
          { pId: 4, id: 3, title: "速写", type: "default", LabelID: "5_3" },
        ]
      }, {
        id: 5,
        plabel: "6",
        title: "音乐",
        iconChecked: "icon",
        majorSub: [
          { pId: 5, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 5, id: 1, title: "视唱", type: "default", LabelID: "6_1" },
          { pId: 5, id: 2, title: "练耳", type: "default", LabelID: "6_2" },
          { pId: 5, id: 3, title: "音乐常识", type: "default", LabelID: "6_3" },
        ]
      }, {
        id: 6,
        plabel: "7",
        title: "播音",
        iconChecked: "icon",
        majorSub: [
          { pId: 6, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 6, id: 1, title: "普通话", type: "default", LabelID: "7_1" },
          { pId: 6, id: 2, title: "即兴评述", type: "default", LabelID: "7_2" },
          { pId: 6, id: 3, title: "文学稿件", type: "default", LabelID: "7_3" },
          { pId: 6, id: 4, title: "新闻稿件", type: "default", LabelID: "7_4" },
          { pId: 6, id: 5, title: "模拟主持", type: "default", LabelID: "7_5" },
          { pId: 6, id: 6, title: "模拟配音", type: "default", LabelID: "7_6" },
        ]
      }, {
        id: 7,
        plabel: "8",
        title: "编导",
        iconChecked: "icon",
        majorSub: [
          { pId: 7, id: 0, title: "全部", type: "warn", LabelID: "0" },
          { pId: 7, id: 1, title: "故事写作", type: "default", LabelID: "8_1" },
          { pId: 7, id: 2, title: "文学常识", type: "default", LabelID: "8_2" },
          { pId: 7, id: 3, title: "影视写作", type: "default", LabelID: "8_3" },
          { pId: 7, id: 4, title: "面试", type: "default", LabelID: "8_4" },
        ]
      },
      ],
    }
  },
  data: {
    plabel:0,
    label:0,
    index: 0,
    majorId: 0,
    customId: 0,
    priceId: 0,
    majorList: [
      { title: "全部", id: "0", type: "warn" },
      { title: "舞蹈", id: "1", type: "default" },
      { title: "表演", id: "2", type: "default" },
      { title: "空乘", id: "3", type: "default" },
      { title: "美术", id: "4", type: "default" },
      { title: "书法", id: "5", type: "default" },
      { title: "音乐", id: "6", type: "default" },
      { title: "播音", id: "7", type: "default" },
      { title: "编导", id: "8", type: "default" },
      { title: "其他", id: "9", type: "default" },
    ],
    customList: [
      { title: "全部", id: "0", type: "warn" },
      { title: "入门", id: "1", type: "default" },
      { title: "进阶", id: "2", type: "default" },
      { title: "备考", id: "3", type: "default" }
    ],
    priceList: [
      { title: "全部", id: "0", type: "warn" },
      { title: "免费", id: "1", type: "default" },
      { title: "付费", id: "2", type: "default" }

    ],
    // accordion-begin
    all: {
      title: "全部",
      type: "warn"
    },
    // accordion-end
    selectHidden: true
  },
  methods: {
    onSelectAll: function () {
      var all = this.data.all;
      all.type = "warn";
      this.setData({
        all: all
      });
      util.reset(this);
    },
    onSwitchAccordion: function (e) {
      var et = e;
      var that = this;
      util.switchAccordion(et, that);
    },
    // search-all begin
    onShowResult: function (e) {
      var SearchKey = e.detail.value;
      this.setData({
        SearchKey: SearchKey
      });
      this.triggerEvent("onShowResult");
    },
    onGetSearchKey: function () {
      return this.data.SearchKey;

    },
    // search-all end
    onFocus:function(){
      this.setData({
        selectHidden:true
      });
    },
    onPicker:function(){
       this.setData({
         selectHidden:true
       });
    },
    onPickerChange: function (e) {
      var index = e.detail.value;
      this.setData({
        index: index
        
      });
      this.triggerEvent("onPickerChange");
    },
    onGetIndex: function () {

      return this.data.index;
    },
    onSelect: function () {
      this.triggerEvent("onSelect");
      this.setData({
        selectHidden: false
      });
    },
    onSelectChange: function (e) {
      var id = parseInt(e.target.dataset.id);
      var sort = e.target.dataset.sort;
      var pId = parseInt(e.target.dataset.pid);
      var label =  e.target.dataset.label;
      if (sort == "majorSup") {
        var majorSup = this.data.majorSup;
        util.resetType(majorSup, id, pId);
        this.setData({
          majorSup: majorSup,
          label:label

        });
      }
      if (sort == "major") {
        var majorList = this.data.majorList;
        util.resetType(majorList, id, pId);
        this.setData({
          majorList: majorList,
          majorId: id
        });

      } else if (sort == "custom") {
        var customList = this.data.customList;
        util.resetType(customList, id, pId);
        this.setData({
          customList: customList,
          customId: id
        });
      } else {
        var priceList = this.data.priceList;
        util.resetType(priceList, id, pId);
        this.setData({
          priceList: priceList,
          priceId: id
        });

      }
    },
    onReset: function () {
      this.setData({
        priceId: 0,
        majorId: 0,
        customId: 0,
        plabel:0,
        label:0
      });
      util.reset(this);
    },
    onConfirm: function () {
      this.triggerEvent("onConfirm");
      this.setData({
        selectHidden: true,
      });

    },
    onGetAccordion: function () {
      return {
        ParentLabelID: this.data.plabel,
        LabelID: this.data.label,
        AdaptationType: this.data.customId,
        PriceType: this.data.priceId
      };
    },
    onGetIds: function () {
      return {
        AdaptationType: this.data.customId,
        PriceType: this.data.priceId,
        Subject: this.data.majorId
      }
    }
  }
});